<template>
	<view class="container">
		<view class="intro">本项目已包含uni ui组件，无需import和注册，可直接使用。在代码区键入字母u，即可通过代码助手列出所有可用组件。光标置于组件名称处按F1，即可查看组件文档。</view>
		<text class="intro">详见：</text>
		<uni-link :href="href" :text="href"></uni-link>
	</view>


</template>

<script>
	let app = ""
	export default {
		data() {
			return {
				href: 'https://uniapp.dcloud.io/component/README?id=uniui',
				code: ''

			}
		},
		onLoad: function() {



			this.requestUserProfile();


			//判断当前打开平台
			let _this = this
			app = getApp()
			console.log(app.globalData.platform)
			let platform = app.globalData.platform
			if (platform != 'window' && platform != 'mac') {
				console.log('跳转')
				// uni.redirectTo({
				// 	url:'../phone/home/home'
				// })
				// uni.switchTab({
				// 	url:'../phone/home/home'
				// })


			}

		},
		onShow: function() {
			// console.log('App Show')
		},
		methods: {

			//获取用户信息
			requestUserProfile() {
				var _this = this;
				uni.getUserInfo({
					desc: '登录后可同步数据',
					provider: 'weixin',
					lang: "zh_CN",
					success: (res1) => {
						console.log(res1)
						uni.login({
							provider: 'weixin',
							success: (res) => {
								console.log(res)
								_this.code = res.code;
								if (res.errMsg == 'login:ok') {
									this.getLogin()
								}
							}
						})


					},
					fail: (err) => {
						console.log(err)
					}
				})

			},
			//网络请求示例
			async getLogin() {
				//请求参数
				let parmas = {
					code: this.code
				}
				const res = await this.$myRequest({
					url: "/wx/ma/user/wxbd0eecccbd1db803/login",
					header: {

						"Authorization": "Basic ZG90Z286ZG90Z28=",
						"token": uni.getStorageSync("accessToken") ? uni.getStorageSync("accessToken") : ''
					},
					data: parmas,
					method: 'GET', //默认是GET
				})

				console.log('返回结果', res)
				if (res.data.code == 200) {

				}
			},

			//网络请求示例
			async getData() {
				//请求参数
				let parmas = {}
				const res = await _this.$myRequest({
					url: "",
					header: {
						"Content-Type": "application/x-www-form-urlencoded",
						"Authorization": "Basic ZG90Z286ZG90Z28=",
					},
					data: parmars,
					method: 'POST', //默认是GET
				})
				console.log('返回结果', res)
			},


		}
	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}
</style>
